﻿var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

var phone = sessionStorage.getItem("userPhone");

$(function () {

    if (isiOS) {
        $("#linkSMS").attr("href", "sms:10086&body=XDJSY");
    }
    else {
        $("#linkSMS").attr("href", "sms:10086?body=XDJSY");
    }
    $("#feePhone").text(phone);
    choose();
    choose_submit();
    prompt();
    frame_choose();
    frame_submit();
    cancel();
    $(".try select").change(function () {
        var options = $(".try select option:selected");
        $.post("/HeShengHuo/GetShopListMethod", { 'cityId': options.val(), 'pageType': 3 }, GetCurShopMethodResponse);

    })
    $(".lists .lists-content").click(function () {
        $(".volume-frame").show();
    });
    $(".volume-frame .close-img").click(function () {
        $(".volume-frame").hide();
    });

});

function GetCurShopMethodResponse(data) {
    if (data.Success) {
        var r = data.Message;
        $(".chengdu img").attr("src", "../image/city/" + data.CityId + ".png")
        var str = "";
        if (r.length > 0) {
            for (var i = 0; i < r.length; i++) {
				var strshop = "";
                if (r[i].CityName.length > 1) 
                    strshop = "(" + r[i].CityName + ")";
                str += '<div class="lists"><div class="lists-content" onclick="ShopDetails(' + r[i].ShopId + ',3)">';
                str += '<img src="../image/shoptype/shop_' + r[i].ShopType + '.png" alt=""><div class="lists-logo">';
                str += '<img src="http://fuwu.xdjsclub.com/Shops/images/'+r[i].ImgLogo+'/logo.jpg" alt=""><p>' + r[i].ShopName + strshop + '</p><p>' + r[i].TicketName + '</p></div></div>';
                str += '<div class="lists-btn"><img src="../image/free/btn-lingqu.png" onclick="RecTicket(' + r[i].ShopId + ',\'' + r[i].ShopName + '\')" alt="领取按钮"></div></div>';
            }
        }
        $(".menu").html(str);

    } else {
        layer.msg("系统繁忙，请稍后再试！");
    }
}


function RecTicket(shopId, name) {
    $.post("/HeShengHuo/RecCurTicket", { 'phone': phone, 'shopId': shopId }, GetRecCurTicketResponse);
}

function GetRecCurTicketResponse(data) {
    if (data.Success) {
        window.location.href = "/HeShengHuo/CurrentUser?shopId=" + data.Message;
    } else {
        if (data.Code == 3) {
            return tiyan();
        }
        layer.msg(data.Message);
    }
}



function choose() {
    $(".order-menu li").click(function () {
        $(".order-menu li").removeClass("choosed").addClass("choose");
        $(this).addClass("choosed");
    })
}
function choose_submit() {
    $(".choose-btn").click(function () {
        alert("别点我!")
    })
}
function tiyan() {
  
        $(".tiyan-frame").show();
        //如果未订购
        $(".prompt-frame").show();
        $(".frame-order").hide();
        //            //如果已订购
        //            $(".prompt-frame").hide();
        //            $(".frame-order").show();
        $("body,html").css({
            "overflow": "hidden"
        })
}
function prompt() {
    $(".prompt-frame .tijiao").click(function () {
        $(".prompt-frame").hide();
        $(".frame-order").show();
    })
}
function frame_choose() {
    $(".frame-order-menu li").click(function () {
        $(".frame-order-menu li").removeClass("choosed").addClass("choose");
        $(this).addClass("choosed");
        var type = $(this).attr("data-type");  //类型
        SelectType("linkSMS", type);
    })
}
function frame_submit() {
    $(".frame-choose-btn").click(function () {
        $(".tiyan-frame").hide();
        $("body,html").css({
            "overflow": "auto"
        });
        //这里做提交
    })
}
function cancel() {
    $(".tiyan-frame .close-img").click(function () {
        $(".tiyan-frame").hide();
        $("body,html").css({
            "overflow": "auto"
        });
    })
}